package stack;

import java.util.Arrays;
import java.util.Stack;

public class MyStack {
    static int[] elems;
    static final int DEFAULT_CAPACITY = 10;
    static int usedSize;

    public MyStack () {
        elems = new int[DEFAULT_CAPACITY];
        usedSize = 0;
    }

    public void push (int data) {
        grow();
        elems[usedSize++] = data;
    }

    public int peak () {
        if (isEmpty()) {
            throw new RuntimeException();
        }
        return elems[usedSize - 1];
    }

    public void pop () {
        if (isEmpty()) {
            return;
        }
        usedSize--;
    }

    public void grow () {
        if (isFull()) {
            elems = Arrays.copyOf(elems, elems.length + 1);
        }
    }

    public boolean isFull () {
        if (usedSize >= elems.length) {
            return true;
        }
        return false;
    }

    public boolean isEmpty() {
        if (this.usedSize == 0) {
           return true;
        }
        return false;
    }
}

class Ts {
    public static void main(String[] args) {
//        Stack<Integer> stack = new Stack<>();
        MyStack stack = new MyStack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        System.out.println(stack.peak());
        stack.pop();
        System.out.println(stack.peak());
        System.out.println(stack.isEmpty());
    }
}
